import 'dart:async';

import 'package:flutter_ncsjqz_getx/page/home/home_view.dart';
import 'package:get/get.dart';

class LoadingLogic extends GetxController {
  /// 倒计时长度
  int oldCount = 2;
  
  /// 正在倒计时
  int newCount = 2;

  /// 计时器
  Timer? timer;

  /// 开始倒计时LoginPage
  setOldTimer(){
    timer = Timer.periodic(Duration(seconds: 1), (timer) {
      newCount--;
      if(newCount == 0) {
        cancelTimer();
        Get.off(()=>HomePage());
      }
      update();
    });
  }

  /// 结束倒计时
  cancelTimer(){
    if(timer!=null) {
      newCount = oldCount;
      timer!.cancel();
    }
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    cancelTimer();
  }
}
